﻿import flash.display.BitmapData;
/**
 * ...
 * @author	Kliment
 * @version	0.1.0
 */

class kliment.data.BMP {
	
	public static function encode(bitmp:BitmapData, alpha:Boolean):Array {
		var forReturn:Array = new Array();
		var width:Number = Math.ceil(bitmp.width);
		var height:Number = Math.ceil(bitmp.height);
		var funct:String = "bitmp." + (alpha?"getPixel32":"getPixel");
		for (var y:Number = 0; y < height; y++) {
			var line:Array = new Array();
			for (var x:Number = 0; x < width; x++) {
				line.push(funct(x, y));
			}
			forReturn.push(line);
		}
		return forReturn;
	}
	
	public static function decode(array:Array):BitmapData {
		var width:Number = array[0].length;
		var height:Number = array.length;
		
		var forReturn:BitmapData = new BitmapData(width, height, false, 0x000000);
		for (var y:Number = 0; y < height; y++) {
			for (var x:Number = 0; x < width; x++) {
				forReturn.setPixel(x, y, array[x][y]);
			}
		}
		return forReturn;
	}
}